package eu.otherweb.json;

import java.lang.reflect.Type;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

public class LengthTypeConverter implements JsonSerializer<Length>, JsonDeserializer<Length> {

    @Override
    public Length deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
        return new Length(json.getAsString());
    }

    @Override
    public JsonElement serialize(Length src, Type srcType, JsonSerializationContext context) {
        return new JsonPrimitive(src.toString());
    }
}